package com.xhtech.base.view.viewpage.wpage

import androidx.viewpager.widget.ViewPager

/**
 * @创建者：yuan_xh
 * @创建时间：2021/3/23 10:17
 * @描述：
 */
class WViewPageHelper(var viewPager: ViewPager) {
    var scroller: WScroller? = null

    private fun init() {
        scroller = WScroller(viewPager.context)
        val cl = ViewPager::class.java
        try {
            //利用反射设置mScroller域为自己定义的WScroller，这里的命名（‘mScroller’）不能随意改
            val field = cl.getDeclaredField("mScroller")
            field.isAccessible = true
            field[viewPager] = scroller
        } catch (e: NoSuchFieldException) {
            e.printStackTrace()
        } catch (e: IllegalAccessException) {
            e.printStackTrace()
        }
    }

    init {
        init()
    }
}